﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.IO;

namespace ModelPredictPro.WindowForms.AppCodes {
    public class FileHelper {
        public static bool IsBatchFile(string path, out string[] fileNames) {
            fileNames = null;
            int index = path.LastIndexOf(Path.DirectorySeparatorChar);
            if (index < 0) { return false; }
            string dir = path.Substring(0, index);
            if (!Directory.Exists(dir)) { return false; }
            string searchPattern = path.Substring(index + 1);
            fileNames = Directory.GetFiles(dir, searchPattern);
            return true;
        }


        public static string GetOutputPath(string source, string outputPattern) {
            FileInfo file = new FileInfo(source);
            string name = Path.GetFileNameWithoutExtension(file.FullName);
            string extention = file.Extension == "" ? "" : file.Extension.Substring(1);
            return string.Format(outputPattern, file.Directory.FullName, name, extention);
        }
        public static string[] GetNFoldFileNames(string template, int nfold){
            string[]rst = new string[nfold];
            for (int i = 0; i < nfold; i++) {
                rst[i] = string.Format(template, "", nfold + 1);
            }
            return rst;
        }

    }
}
